﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.Appointments;
using YaAppoint.Appointments.PlanPools;

namespace YaAppoint.Controllers
{
    public class PlanPoolController: AbpController
    {

        private readonly IPlanPoolAppService _planPoolAppService;

        public PlanPoolController(IPlanPoolAppService planPoolAppService)
        {
            _planPoolAppService = planPoolAppService;
        }

        /// <summary>
        /// 生成排班表格数据
        /// </summary>
        [HttpGet("/api/plan-pool/get-tab-data")]
        public async Task<IActionResult> GetTableData(Guid sid)
        {
            return new JsonResult(await _planPoolAppService.GetTableData(sid));
        }


        /// <summary>
        /// 提交新建
        /// </summary>
        [HttpPost("/api/plan-pool/submit-create")]
        public async Task<IActionResult> SubmitCreate([FromBody] CreatePlanPoolDto dto, [FromQuery] Guid sid)
        {
            return new JsonResult(await _planPoolAppService.SubmitCreate(dto,sid));
        }

        /// <summary>
        /// 提交编辑
        /// </summary>
        [HttpPost("/api/plan-pool/submit-edit")]
        public async Task<IActionResult> SubmitEdit([FromBody] PlanPoolDto dto)
        {
            return new JsonResult(await _planPoolAppService.SubmitEdit(dto));
        }

        /// <summary>
        ///  批量新建
        /// </summary>
        [HttpPost("/api/plan-pool/batch-create")]
        public async Task<IActionResult> BatchCreate([FromBody] BatchModelDto batchModel, [FromQuery] Guid sid)
        {
            return new JsonResult(await _planPoolAppService.BatchCreate(batchModel,sid));
        }

        /// <summary>
        /// 获取详情
        /// </summary>
        [HttpGet("/api/plan-pool/get")]
        public async Task<IActionResult> GetAsync(Guid id)
        {
            return new JsonResult( await _planPoolAppService.GetAsync(id));
        }

        /// <summary>
        /// 删除
        /// </summary>
        [HttpDelete("/api/plan-pool/delete")]
        public async Task<IActionResult> DeletePlanPool(Guid id)
        {
            return new JsonResult(await _planPoolAppService.DeletePlanPool(id));
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        [HttpPost("/api/plan-pool/delete-many")]
        public async Task<IActionResult> DeleteMany([FromBody]List<Guid> idList)
        {
            return new JsonResult( await  _planPoolAppService.DeleteMany(idList));
        }

        /// <summary>
        /// 清空
        /// </summary>
        [HttpDelete("/api/plan-pool/delete-all")]
        public async Task<IActionResult> DeleteAll(Guid sid)
        {
            return new JsonResult( await  _planPoolAppService.DeleteAll(sid));
        }


        /// <summary>
        /// PlanPool组件获取号池详情
        /// </summary>
        [HttpGet("/api/plan-pool/get-table-plan-pool")]
        public async Task<IActionResult> GetTablePlanPool(Guid sid, DayInWeek weekDay, Guid intervalId)
        {
            return new JsonResult(await _planPoolAppService.GetTablePlanPool(sid, weekDay, intervalId));
        }
    }
}
